<template>
    <div class="newsinfo">
        <h3 class="title">{{newsinfo.title}}</h3>
        <p class="subtitle">
            <span>发表时间: {{newsinfo.add_time | dataFormat}}</span>
            <span>点击: {{newsinfo.click}} 次</span>
        </p>
        <hr>
        <div class="content" v-html="newsinfo.content"></div>
        <!-- 评论子组件 -->
        <comment :id="this.id"></comment>
    </div>
</template>

<script>
//导入评论子组件
import comment from '../subcomponents/comment'
export default {
    data(){
        return{
            id:this.$route.params.id,//将url中传来的id挂载到data上
            newsinfo:[]
        }
    },
    created() {
        this.GetNewsInfo()
    },
    methods: {
        GetNewsInfo(){
            this.$ajax({url:"http://www.liulongbin.top:3005/api/getnew/" + this.id,method:'GET'})
            .then(ret =>{
                if(ret.data.status === 0){
                    this.newsinfo = ret.data.message[0];
                }else{
                    Toast('获取新闻列表失败!')
                }
            })
        }
    },
    components:{
        comment
    }
}
</script>

<style scoped>
    .newsinfo{
        padding: 5px;
        margin-top: 46px;
    }
    .title{
        font-size: 20px;
        text-align: center;
        margin: 15px 0;
        color: red;
    }
    .subtitle{
        font-size: 13px;
        color: #226aff;
        display: flex;
        justify-content: space-between;
    }
</style>